package com.icode.dao.impl;

import com.icode.core.dto.order.PageDTO;
import com.icode.core.model.about.Faq;
import com.icode.dao.FaqDao;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: song
 * Date: 15-12-9
 * Time: 下午4:43
 * To change this template use File | Settings | File Templates.
 */
@Repository("faqDao")
public class FaqDaoImpl extends EntityDaoImpl implements FaqDao {

    @Override
    public List<Faq> findFaqs(String keywords) {
        String hql = "from " + Faq.class.getName() + " e where e.question like:question";
        Query query = currentSession().createQuery(hql);
        query.setParameter("question", "%" + keywords + "%");
        return query.list();
    }

    @Override
    public void deleteObject(Object obj) {
        currentSession().delete(obj);
    }

    @Override
    public List<Faq> findAllByPage(String currentPage) {
        String hql ="from " +Faq.class.getName();
        Query query =currentSession().createQuery(hql);
        query.setFirstResult((Integer.parseInt(currentPage) - 1) * PageDTO.pageOfData);
        query.setMaxResults(PageDTO.pageOfData);
        return query.list();
    }
}
